/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.buzz.parent.service;

import java.util.List;

import com.jeeplus.modules.adjunctFile.entity.AdjunctFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.buzz.parent.entity.Parent;
import com.jeeplus.modules.buzz.parent.mapper.ParentMapper;
import com.jeeplus.modules.buzz.parent.entity.Parententry;
import com.jeeplus.modules.buzz.parent.mapper.ParententryMapper;

/**
 * 家长登记Service
 * @author 陈
 * @version 2025-06-16
 */
@Service
@Transactional(readOnly = true)
public class ParentService extends CrudService<ParentMapper, Parent> {

	@Autowired
	private ParententryMapper parententryMapper;

	public Parent get(String id) {
		Parent parent = super.get(id);
		parent.setParententryList(parententryMapper.findList(new Parententry(parent)));
		return parent;
	}




	public List<Parent> findList(Parent parent) {
		return super.findList(parent);
	}

	public Page<Parent> findPage(Page<Parent> page, Parent parent) {
		return super.findPage(page, parent);
	}

	@Transactional(readOnly = false)
	public void save(Parent parent) {
		super.save(parent);
		for (Parententry parententry : parent.getParententryList()){
			if (parententry.getId() == null){
				continue;
			}
			if (Parententry.DEL_FLAG_NORMAL.equals(parententry.getDelFlag())){
				if (StringUtils.isBlank(parententry.getId())){
					parententry.setInterid(parent);
					parententry.preInsert();
					parententryMapper.insert(parententry);
				}else{
					parententry.preUpdate();
					parententryMapper.update(parententry);
				}
			}else{
				parententryMapper.delete(parententry);
			}
		}
	}

	@Transactional(readOnly = false)
	public void delete(Parent parent) {
		super.delete(parent);
		parententryMapper.delete(new Parententry(parent));
	}

}
